/*


 */

package jas.util;


import java.io.Serializable;
import java.util.HashMap;

/**
 *
 *
 */
public class HashBijectiveMap<Primary, Secondary> implements BijectiveMap<Primary, Secondary>, Serializable {
    
    private HashMap<Primary, Secondary> primeToSecond = new HashMap<Primary, Secondary>();
    private HashMap<Secondary, Primary> secondToPrime = new HashMap<Secondary, Primary>();

    public void add(Primary primary, Secondary secondary) {
        primeToSecond.put(primary, secondary);
        secondToPrime.put(secondary, primary);
    }

    public Primary getPrimary(Secondary secondary) {
        return secondToPrime.get(secondary);
    }

    public Secondary getSecondary(Primary primary) {
        return primeToSecond.get(primary);
    }

    public void removePrimary(Primary primary) {
        Secondary sec = primeToSecond.get(primary);
        primeToSecond.remove(primary);
        secondToPrime.remove(sec);
    }

    public void removeSecondary(Secondary secondary) {
        Primary pri = secondToPrime.get(secondary);
        secondToPrime.remove(secondary);
        primeToSecond.remove(pri);
    }

}
